package demo.practice.leetcode_msjd;

public class Msjd0301 {

    public static void main(String[] args) {
        TripleInOne tripleInOne= new TripleInOne(1);
        tripleInOne.push(0,1);
        tripleInOne.push(0,2);

        System.out.println(tripleInOne.pop(0));
        System.out.println(tripleInOne.pop(0));
        System.out.println(tripleInOne.pop(0));

        System.out.println(tripleInOne.isEmpty(0));

    }

}

class TripleInOne{
    int [] arr;
    int s0;
    int s1;
    int s2;
    int stackSize;

    public TripleInOne(int stackSize) {
        this.arr= new int[stackSize*3];
        this.stackSize=stackSize;
        this.s0= 0;
        this.s1= stackSize;   //0+stackSize
        this.s2= stackSize<<1;//s0+stackSize+stackSize;
    }

    public void push(int stackNum, int value) {
        if( stackNum==0 && s0<stackSize){
            arr[s0++]=value;
        }

        if( stackNum==1 && s1<2*stackSize){
            arr[s1++]=value;
        }

        if( stackNum==2 && s2<3*stackSize){
            arr[s2++]=value;
        }
    }

    public int pop(int stackNum) {
        if( stackNum==0 && s0>0){
            return arr[--s0];
        }else if( stackNum==1 && s1>stackSize){
            return arr[--s1];
        }else if( stackNum==2 && s2>2*stackSize){
            return arr[--s2];
        }
        return -1;
    }

    public int peek(int stackNum) {
        if( stackNum==0&& s0>0){
            return arr[s0-1];
        }else if( stackNum==1&& s1>stackSize ){
            return arr[s1-1];
        }else if( stackNum==2&& s2>2*stackSize){
            return arr[s2-1];
        }

        return -1;
    }

    public boolean isEmpty(int stackNum) {
        if( stackNum==0){
            return s0==0;
        }else if( stackNum==1 ){
            return s1==stackSize;
        }else if( stackNum==2){
            return s2==2*stackSize;
        }

        throw new RuntimeException("stackNum erro");
    }
}